{% load staticfiles %}
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="{% static 'h-ui/css/H-ui.min.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'h-ui.admin/css/H-ui.admin.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'lib/Hui-iconfont/1.0.8/iconfont.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'h-ui.admin/skin/default/skin.css' %}" id="skin" />
    <link rel="stylesheet" type="text/css" href="{% static 'h-ui.admin/css/style.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'lib/select2/css/select2.min.css' %}"/>

    <script type="text/javascript" src="{% static 'lib/jquery/1.9.1/jquery.min.js' %}"></script>
    <script type="text/javascript" src="{% static 'lib/layer/2.4/layer.js' %}"></script>
    <script type="text/javascript" src="{% static 'h-ui/js/H-ui.js' %}"></script>
    <script type="text/javascript" src="{% static 'lib/select2/js/select2.full.min.js' %}"></script>

    <title>Title</title>
</head>

<body>
    <div class="Huialert Huialert-info">请选择需要授权用户，然后保存。</div>
    <br/>
    <form id="userForm" method="post" action="">
        <select class="select-multiple-user" name="selectUser" multiple="multiple" style="width:100%;">
            {% for user in users %}
            <option value="{{ user.id }}" selected>{{ user }}</option>
            {% endfor %}
            {% for guest in guests %}
            <option value="{{ guest.id }}">{{ guest }}</option>
            {% endfor %}
        </select>
        <input name="app_id" value="{{ app_id }}" hidden/>
        <input name="action_id" value="{{ action_id }}" hidden/>
        <input name="env_id" value="{{ env_id }}" hidden/>
        <br/><br/><br/>
        <div class="r">
            <button class="btn btn-danger radius" id="saveBtn" type="button">保存修改</button>
        </div>
    </form>

<script>
$(document).ready(function () {
    $('.select-multiple-user').select2({
        placeholder: "点击鼠标，可下拉选择，也可输入再选择",
        allowClear: true
    });
    $('#saveBtn').click(function (e) {
        e.preventDefault();
        var group_data = $('#userForm').serialize();
        console.log(group_data);
        $.ajax({
            type:'POST',
            data:{
                group_data:group_data,
            },
            url:"{% url 'rightadmin:update_permission' %}",
            dataType:"json",
            success:function (data) {
                console.log(data);
                if (data['return'] == 'error'){
                    $("body").Huimodalalert({content: "<span class='c-danger'>您没有权限更新！</span>", speed: 3000});
                }
                if (data['return'] == 'success') {
                    $("body").Huimodalalert({content: "<span class='c-success'>权限更改成功！</span>", speed: 3000});
                }
            },
            error:function () {
                $("body").Huimodalalert({content: "<span class='c-danger'>系统出现问题</span>", speed: 3000});
            }
        });
    });
});
</script>

</body>
</html>